package cn.sgjk.train.batch.job;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.sgjk.train.batch.Feign.BusinessFeign;
import cn.sgjk.train.common.resp.CommonResp;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;


@DisallowConcurrentExecution
public class DailyTrain implements Job {

    private static final Logger LOG = LoggerFactory.getLogger(DailyTrain.class);

    @Autowired
    private BusinessFeign businessService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 增加日志流水号
        MDC.put("LOG_ID", System.currentTimeMillis() + RandomUtil.randomString(3));
        LOG.info("执行每日车次定时任务 开始");
        Date date = new Date();
        DateTime dateTime = DateUtil.offsetMinute(date, 20);
        Date offsetTime = dateTime.toJdkDate();
        CommonResp<Object> CommonResp = businessService.genAll(offsetTime);
        LOG.info("执行每日车次定时任务 结束:{}",CommonResp);
    }
}
